var arr=[5,8,55,32,99]

arr.softlsort = function(fn)
{
    for(var j=0; j<this.length; j++)
    {
        var item =this[j]
        var idx=0
        for (var i=j+1; i<this.length; i++)
        {
            if (fn(item,this[i]))
            {
            item=this[i]
            idx =i

        }
    }
        if (this[j] !==item)
        {
            var a =this[j]
            this[j]=this[idx]
            this[idx]=a
        }
        console.log(arr)
    }

}

console.log('数组小到大排序');

arr.softlsort(function(a,b)
{
    return a>b
}
)

console.log('数组大到小排序');

arr.softlsort(function(a,b)
{
    return a<b
}
)

console.log('使用a-b原理');

arr.softlsort = function(fn)
{
    for(var j=0; j<this.length; j++)
    {
        var item =this[j]
        var idx=0
        for (var i=j+1; i<this.length; i++)
        {
            if (fn(item,this[i])>0)
            {
            item=this[i]
            idx =i
        }  
    }
        if (this[j] !==item)
        {
            var a =this[j]
            this[j]=this[idx]
            this[idx]=a
        }
        console.log(arr)
    }

}

arr.softlsort(function(a,b)
{
    return a-b
}
)





